// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  if (event.action == "add") {
    return await db.collection('video')
    .add({
      data: {
        id: event.obj.id,
        commentNum: event.obj.commentNum,
        header: event.obj.header,
        name: event.obj.name,
        passtime: event.obj.passtime,
        text: event.obj.text,
        up: event.obj.up,
        videoUrl: event.obj.videoUrl
      }
    })
  }
  if (event.action == "delete") {
    return await db.collection('video')
    .where({
      videoUrl: event.url
    })
    .remove()
  }
}